package ro.uaic.info.fmse.context.transformers.filters;

import java.util.ArrayList;
import java.util.List;

import ro.uaic.info.fmse.context.transformers.generic.Tree;
import ro.uaic.info.fmse.context.transformers.items.ConfigurationNode;

public class LessNodesFilter implements AbstractFilter {

	public List<Tree<ConfigurationNode>> filter(
			List<Tree<ConfigurationNode>> solutions) {
		
		List<Tree<ConfigurationNode>> list = new ArrayList<Tree<ConfigurationNode>>();
		int min = -1;
		
		// find minimum
		for(Tree<ConfigurationNode> t : solutions)
		{
			if (min == t.getNodes().size())
				list.add(t);
			else if (min == -1 || min > t.getNodes().size())
			{
				min = t.getNodes().size();
				
				list.clear();
				
				list.add(t);
			}
			
		}
		
		
		return list.size() > 0 ? list : null;
	}

}
